<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class ApplicationConfig 
{
	private static $instance;
	
	private function __construct() 
    {
    }
	
	public static function app()
	{
		if (!isset(self::$instance)) 
		{
	            $c = __CLASS__;
	            self::$instance = new $c;
	            //self::$instance->themeJsUrl = 'jsURLLLLL';
	            self::$instance->setParams();
	     }

        return self::$instance;	
	}
	
	public function setParams()
	{
		$array['base'] = array(
								'jsUrl' => Yii::app()->baseUrl . '/js/',
		 						'cssUrl' => Yii::app()->baseUrl . '/css/',
								'imageUrl' => Yii::app()->baseUrl . '/images/',
								);
	

		$array['folder_path'] = array(
								'bannerImages' => YiiBase::getPathOfAlias('webroot.banner_images').'/',
								'propertyImagesNormal' => YiiBase::getPathOfAlias('webroot.property_images_normal').'/',
								'propertyImagesMedium' => YiiBase::getPathOfAlias('webroot.property_images_medium').'/',
								'propertyImagesThumbnail' => YiiBase::getPathOfAlias('webroot.property_images_thumbnail').'/',
								);						

		$array['url_path'] = array(
								'bannerImages' => Yii::app()->baseUrl. '/banner_images/',
								'propertyImages' => Yii::app()->baseUrl. '/property_images/',
								'propertyImagesNormal' => Yii::app()->baseUrl. '/property_images_normal/',
								'propertyImagesMedium' => Yii::app()->baseUrl. '/property_images_medium/',
								'propertyImagesThumbnail' => Yii::app()->baseUrl. '/property_images_thumbnail/',
								);						
								
						
		$array['module'] = array(
								'admin' => 'admin',
								'company'=>'company',
								'client'=>'client',
								);				
		$this->params = $array;
	}
	
	public static function getImageUrl($type, $params)
	{
		switch ($type)
		{
			case 'BANNER-IMAGES':
					$folder = "bannerImages";
			break;
			
			case 'PAGE-IMAGES':
					$folder = "pageImages";
			break;
			
			case 'PROPERTY-IMAGES-NORMAL':
					$folder = "propertyImagesNormal";
			break;
			
			case 'PROPERTY-IMAGES-MEDIUM':
					$folder = "propertyImagesMedium";
			break;
			
			case 'PROPERTY-IMAGES-THUMBNAIL':
					$folder = "propertyImagesThumbnail";
			break;
			
		}
		$image_url = ApplicationConfig::app()->params['url_path'][$folder] . $params['file_name'];
		return $image_url;
		
	}
	
	
	public static function getURL($module,$controller,$action,$arrParameter=array(),$config=array())
	{
		$module_name = "";
		if($module !== "" && isset(ApplicationConfig::app()->params['module'][$module]))
		{
			$module_name = ApplicationConfig::app()->params['module'][$module]  ."/";
		}
		
		$url = $module_name . $controller ."/" . $action . "/";
		
		if($controller == "" && $module == "")
		{
			$url = 	$action . "/";
		}

		
		return  Yii::app()->createUrl($url,$arrParameter);
		 
	}
	public static function getCategoryURL($arrParameters)
	{
		if (isset($arrParameters['parent']) && $arrParameters['parent']!="" && isset($arrParameters['child']) && $arrParameters['child']!="")
		{
			$url="category/".$arrParameters['parent']."/".$arrParameters['child'];
		}
		else if (isset($arrParameters['parent']) && $arrParameters['parent']!="")
		{
			$url="category/".$arrParameters['parent'];
		}
		return  Yii::app()->createUrl($url); 
	}
	public static function getPageURL($arrParameters)
	{
		if (isset($arrParameters['parent']) && $arrParameters['parent']!="" && isset($arrParameters['child']) && $arrParameters['child']!="")
		{
			$url='p/'.'pslug='.$arrParameters['parent']."/cslug=".$arrParameters['child'];
		}
		else if (isset($arrParameters['parent']) && $arrParameters['parent']!="")
		{
			$url='slug='.$arrParameters['parent'];
		}
		$url=str_replace('/','&',$url);
		$startUrl='fcg/view&';
		return  Yii::app()->createUrl($startUrl.$url); 
	}
	public static function getPostURL($arrParameters)
	{
	 if (isset($arrParameters['post']) && $arrParameters['post']!="")
		{
			$url=$arrParameters['post'];
		}
		$startUrl='r=fcg/view';
		return  Yii::app()->createUrl($url); 
	}
	
	public static function getBackendUrl($arrParameters)
	{
		if (isset($arrParameters['parent']) && $arrParameters['parent']!="" && isset($arrParameters['child']) && $arrParameters['child']!="")
		{
			$url=$arrParameters['parent']."/".$arrParameters['child'];
		}
		else if (isset($arrParameters['parent']) && $arrParameters['parent']!="")
		{
			$url=$arrParameters['parent'];
		}
		return  Yii::app()->createUrl($url); 
	}
	

	
	public static function getConstantData($type)
	{
		$arrReturn = array();
		switch ($type)
		{
			case 'USER-TYPE':
					$arrReturn = array('client'=>'Client', 'company'=>'Company');
			break;
			
			case 'CURRENCY':
					$arrReturn = array('US'=>'US', 'EURO'=>'EURO');
			break;
		}
		return $arrReturn;
	}
	public static function getArray($type)
    {
        switch($type)
        {
            case "TOP-HORI-MENU":
                $arrLeftMenu = array(
	                array('type'=>'Page','slug'=>'home','title'=>'','class'=>'active'),
	                array('type'=>'Page','slug'=>'about-us','title'=>'','class'=>''),
	                array('type'=>'Category','slug'=>'products','title'=>'','class'=>''),
	                array('type'=>'Page','slug'=>'internationalpartners','title'=>'','class'=>''),
	                array('type'=>'Category','slug'=>'services','title'=>'','class'=>''),
	                array('type'=>'Page','slug'=>'contact-us','title'=>'','class'=>''),
	                array('type'=>'Page','slug'=>'training','title'=>'','class'=>''),
                    );
                    return $arrLeftMenu;
                break;

             case "HEADER-ICONS":
                $arrLeftMenu = array(
	                array('type'=>'Page','slug'=>'location','title'=>'','class'=>'location'),
	                array('type'=>'Page','slug'=>'support','title'=>'','class'=>'support'),
	                array('type'=>'Page','slug'=>'careers','title'=>'','class'=>'careers'),
	                array('type'=>'Page','slug'=>'iso-9001','title'=>'','class'=>'iso'),
	                array('type'=>'Page','slug'=>'admin-login','title'=>'','class'=>'admin'),
                    );
                    return $arrLeftMenu;
                break;   

             case "LEFT-MENU":
				$arrLeftMenu=array(
				array('type'=>'Page','slug'=>'testing','title'=>''),
				array('type'=>'Page','slug'=>'training','title'=>''),
				array('type'=>'Page','slug'=>'other-services','title'=>''),
				array('type'=>'Page','slug'=>'staff-bios','title'=>''),
				array('type'=>'Page','slug'=>'fields-consulting-group-inc','title'=>''),
				array('type'=>'Options','slug'=>'options','title'=>'Options'),
				
					);
				/*
				array(
				array('type'=>'Page','slug'=>'about-us','title'=>'About Us'),
				array('type'=>'Category','slug'=>'products','title'=>'Products'),
				array('type'=>'Page','slug'=>'internationalpartners','title'=>'InterNational Partners'),
				array('type'=>'Category','slug'=>'services','title'=>'Services'),
				array('type'=>'Page','slug'=>'contact-us','title'=>'Contact Us'),
				array('type'=>'Page','slug'=>'training','title'=>'Training'),
				array('type'=>'Category','slug'=>'latest-news','title'=>'Latest News'),
					);
				*/	
					return $arrLeftMenu;
				break;   
				
			case "CONTACT-US-FORM":
				$arrContactUsForm = array(
				//'field0'=>array(),
				'field1'=>array('label'=>'label','label_name'=>'Name','tag'=>'input','field_name'=>'name','type'=>'text','default_value'=>'default value name box', 'validation_rules'=>'required'),
				'field2'=>array('label'=>'label','label_name'=>'Company','tag'=>'input','field_name'=>'company','type'=>'text','default_value'=>'default value@gmail.com', 'validation_rules'=>''),
				'field3'=>array('label'=>'label','label_name'=>'Email','tag'=>'input','field_name'=>'email','type'=>'text','default_value'=>'default value quer box', 'validation_rules'=>'required'),
				'field4'=>array('label'=>'label','label_name'=>'Phone','tag'=>'input','field_name'=>'phone','type'=>'text','default_value'=>'default value name box', 'validation_rules'=>''),
				'field5'=>array('label'=>'label','label_name'=>'Mobile','tag'=>'input','field_name'=>'mobile','type'=>'text','default_value'=>'default value@gmail.com', 'validation_rules'=>''),
				'field6'=>array('label'=>'label','label_name'=>'Comment','tag'=>'input','field_name'=>'comment','type'=>'text','default_value'=>'default value quer box', 'validation_rules'=>'required'),
				//'field23'=>array('label'=>'label','label_name'=>'Description','tag'=>'input','filed_name'=>'email','type'=>'text','default_value'=>'@gmail.com', 'validation_rules'=>''),
				'button'=>array('label'=>'','tag'=>'button','value'=>'Submit','field_name'=>'btnquery','type'=>'text','default_value'=>'', 'validation_rules'=>''),
				);
					return $arrContactUsForm ;
				break; 	
        }
     }
	public static function truncateString($text, $nbrChar, $append='...') 
	{
     		if(strlen($text) > $nbrChar) {
          		$text = substr($text, 0, $nbrChar);
          		$text .= $append;
     		}
    		return $text;
	}
	
	public static function propertyStatus($status)
	{
		if(isset($status))
		{
			if($status == "active")
			{
				$return = "Inactive";
			}
			elseif ($status == "inactive")
			{
				$return =  "Active";
			}
			else 
				$return =  null; 
		}
		return $return ;
	}
	
	public static function linkSeprator($status)
	{
		if(isset($status))
		{
			if($status == "active" || $status == "inactive")
			{
				$return = "&nbsp||&nbsp";
			}
			
			else 
				$return =  null; 
		}
		return $return ;
	}
	
	public static function getNameFromIds($type,$id)
	{
		switch ($type)
		{
			case 'COUNTRY-NAME':
				$arrParams = array('country_id'=>$id);
				$objCountry = Country::model()->getModel('BY-COUNTRY-ID', $arrParams);
				if (isset($objCountry) && $objCountry != null && isset($objCountry->name) && $objCountry->name != null)
					$return = $objCountry->name;
				else 
					$return = 'N/A';	
			break;
			
			case 'STATE-NAME':
				$arrParams = array('state_id'=>$id);
				$objState = State::model()->getModel('BY-STATE-ID', $arrParams);
				if (isset($objState) && $objState != null && isset($objState->name) && $objState->name != null)
					$return = $objState->name;
				else 
					$return = 'N/A';
			break;
			
			case 'CITY-NAME':
				$arrParams = array('city_id'=>$id);
				$objCity = City::model()->getModel('BY-CITY-ID', $arrParams);
				if (isset($objCity) && $objCity != null && isset($objCity->name) && $objCity->name != null)
					$return = $objCity->name;
				else 
					$return = 'N/A';
			break;			
		}	
		return $return;
	}
	
	public static function getImagedimensions($type)
	{
		switch ($type)
		{
			case 'normal':
			return array('scale'=>99);
			break;
			
			case 'medium':
			return array('width'=>220, 'height'=>140);
			break;
			
			case 'thumbnail':
			return array('width'=>120, 'height'=>80);
			break;			
		}
	}
	
	public static function getServerName()
	{
		return isset(Yii::app()->request->serverName) ? Yii::app()->request->serverName : null ;
	}
}